package com.ruoyi.ssh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ssh.domain.Subject;
import com.ruoyi.ssh.service.ISubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科目管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/ssh/subject")
public class SubjectController extends BaseController
{
    @Autowired
    private ISubjectService subjectService;

    /**
     * 查询科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subject subject)
    {
        startPage();
        List<Subject> list = subjectService.selectSubjectList(subject);
        return getDataTable(list);
    }

    /**
     * 导出科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:export')")
    @Log(title = "科目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subject subject)
    {
        List<Subject> list = subjectService.selectSubjectList(subject);
        ExcelUtil<Subject> util = new ExcelUtil<Subject>(Subject.class);
        util.exportExcel(response, list, "科目管理数据");
    }

    /**
     * 获取科目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(subjectService.selectSubjectById(id));
    }

    /**
     * 新增科目管理
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:add')")
    @Log(title = "科目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subject subject)
    {
        return toAjax(subjectService.insertSubject(subject));
    }

    /**
     * 修改科目管理
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:edit')")
    @Log(title = "科目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subject subject)
    {
        return toAjax(subjectService.updateSubject(subject));
    }

    /**
     * 删除科目管理
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:remove')")
    @Log(title = "科目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(subjectService.deleteSubjectByIds(ids));
    }

    /**
     * 批量启用科目
     */
    @PreAuthorize("@ss.hasPermi('ssh:subject:edit')")
    @Log(title = "科目管理", businessType = BusinessType.UPDATE)
    @PutMapping("/enable")
    public AjaxResult enable(@RequestBody Integer[] ids) {
        return toAjax(subjectService.enableSubjectByIds(ids));
    }

    /**
     * 获取所有科目名称以及id
     */

    @GetMapping("/allNameAndId")
    public AjaxResult getAllNameAndId() {
        return success(subjectService.selectAllSubjectNameAndId());
    }


    @PreAuthorize("@ss.hasPermi('ssh:subject:query')")
    @GetMapping("/allNameAndId1")
    public AjaxResult getAllNameAndId1() {
        return success(subjectService.selectAllSubjectNameAndId());
    }

}
